﻿using Nest;
using System;

namespace Infrastructure.ElasticSearch.ParentChilds
{
    public class CountBaseSpecification<T> : ISearchSpecification<ICountRequest<T>> where T : class
    {
        private readonly ISearchSpecification<ISearchRequest<T>> _query;

        public CountBaseSpecification(ISearchSpecification<ISearchRequest<T>> query)
        {
            _query = query ?? throw new ArgumentNullException($"{nameof(query)} cannot be null.");
        }

        public ICountRequest<T> IsSatisfiedBy()
        {
            var search = new CountDescriptor<T>()
                .Query(q => _query
                    .IsSatisfiedBy()
                    .Query
                );



            return search;
        }

    }
}